<!DOCTYPE html PUBLIC "-//W3C//DTD//XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>CSSOM - Computed Style - Serialization - Color</title>
    <link rel="author" title="Glenn Adams" href="mailto:glenn@skynav.com"/>
    <link rel="help" href="http://www.w3.org/TR/cssom/#the-cssstyledeclaration-interface"/>
    <meta name="flags" content="dom"/>
    <script src="/resources/testharness.js"/>
    <script src="/resources/testharnessreport.js"/>
  </head>
  <body>
    <div id="log"></div>
    <div id="box"></div>
    <script><![CDATA[
      var elt = document.getElementById('box');

      function trimFinalDelimiter(s) {
        s = s.trim();
        if ( ( s.length > 0 ) && ( s.lastIndexOf(";") == ( s.length - 1 ) ) ) {
          s = s.substring(0,s.length - 1);
        }
        return s;
      }

      test(function(){

        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'\', get computed \'rgb(0, 0, 0)\'');

      test(function(){

        elt.style.color = "black";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'black\', get computed \'rgb(0, 0, 0)\'');

      test(function(){

        elt.style.color = "red";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 0, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'red\', get computed \'rgb(255, 0, 0)\'');

      test(function(){

        elt.style.color = "lime";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 255, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'lime\', get computed \'rgb(0, 255, 0)\'');

      test(function(){

        elt.style.color = "blue";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'blue\', get computed \'rgb(0, 0, 255)\'');

      test(function(){

        elt.style.color = "white";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 255, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'white\', get computed \'rgb(255, 255, 255)\'');

      test(function(){

        elt.style.color = "rgb(0,0,0)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(0,0,0)\', get computed \'rgb(0, 0, 0)\'');

      test(function(){

        elt.style.color = "rgb(255,0,0)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 0, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(255,0,0)\', get computed \'rgb(255, 0, 0)\'');

      test(function(){

        elt.style.color = "rgb(256,0,0)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 0, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(256,0,0)\', get computed \'rgb(255, 0, 0)\'');

      test(function(){

        elt.style.color = "rgb(0,255,0)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 255, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(0,255,0)\', get computed \'rgb(0, 255, 0)\'');

      test(function(){

        elt.style.color = "rgb(0,256,0)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 255, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(0,256,0)\', get computed \'rgb(0, 255, 0)\'');

      test(function(){

        elt.style.color = "rgb(0,0,255)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(0,0,255)\', get computed \'rgb(0, 0, 255)\'');

      test(function(){

        elt.style.color = "rgb(0,0,256)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(0,0,256)\', get computed \'rgb(0, 0, 255)\'');

      test(function(){

        elt.style.color = "rgb(255,255,255)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 255, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(255,255,255)\', get computed \'rgb(255, 255, 255)\'');

      test(function(){

        elt.style.color = "rgb(256,256,256)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 255, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(256,256,256)\', get computed \'rgb(255, 255, 255)\'');

      test(function(){

        elt.style.color = "rgb(-1,256,256)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 255, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(-1,256,256)\', get computed \'rgb(0, 255, 255)\'');

      test(function(){

        elt.style.color = "rgb(256,-1,256)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 0, 255)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(256,-1,256)\', get computed \'rgb(255, 0, 255)\'');

      test(function(){

        elt.style.color = "rgb(256,256,-1)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(255, 255, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(256,256,-1)\', get computed \'rgb(255, 255, 0)\'');

      test(function(){

        elt.style.color = "rgb(-1,-1,-1)";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");
        elt.style.color = "";
        assert_equals(trimFinalDelimiter(getComputedStyle(elt).color), "rgb(0, 0, 0)");

      }, 'set color \'rgb(-1,-1,-1)\', get computed \'rgb(0, 0, 0)\'');
    ]]>
    </script>
  </body>
</html>
